home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dd / breakpoints.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  5KB  |  200 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. #include    "defs.h"
  7. #include    "dbug_protos.h"
  8.  
  9. // ************************************************************************
  10.  
  11. Prototype WORD        RefreshBreakpoints(WORD maxLines, BOOL fullRefresh);
  12. Prototype BOOL        UpBreak(void);
  13. Prototype BOOL        DownBreak(void);
  14.  
  15. Prototype void        InitBreakpoints(void);
  16. Prototype void        InstallBreakpoints(void);
  17. Prototype void        CheckBreakpoints(void);
  18. Prototype BOOL        IsBreakpoint(ULONG address);
  19. Prototype BOOL        SetBreakpoint(ULONG address, UWORD count, UWORD type);
  20. Prototype BOOL        ClearBreakpoint(ULONG address);
  21. Prototype void        SetTempBreakpoint(ULONG address);
  22. Prototype void        SetAllBreakpoints(void);
  23. Local     BOOL        setbp(short i, ULONG address, UWORD count, UWORD type);
  24.  
  25. // ************************************************************************
  26.  
  27. Prototype WORD topBP;
  28.  
  29. BP    bpTable[MAXBP];         // 32 user breakpoints
  30. BP    bpTemp;             // temporary breakpoint
  31. WORD    topBP = 0;            // top breakpoint displayed from table
  32.  
  33. BOOL    UpBreak(void) {
  34.  
  35.     if(topBP > 0) {
  36.         ScrScrolldown();
  37.         topBP--;
  38.         RefreshWindow(FALSE);
  39.     }
  40.     return(TRUE);
  41. }
  42.  
  43. BOOL    DownBreak(void) {
  44.     if(topBP < (MAXBP-1)) {
  45.         ScrScrollup();
  46.         topBP++;
  47.         RefreshWindow(FALSE);
  48.     }
  49.     return(TRUE);
  50. }
  51.  
  52. WORD    RefreshBreakpoints(WORD maxLines, BOOL fullRefresh) {
  53.     WORD        i = MAXBP - topBP;
  54.     static char    *stateTable[] = { "UNSET", "SET  ", "GROUP" };
  55.     WORD        count = 0;
  56.  
  57.     do_scroller();
  58.     if (fullRefresh != -1)SetTitle(NULL,NULL);
  59.     SetTitle(NULL,NULL);
  60.     ScrPlain(); 
  61.     ScrInverse();
  62.     ScrPuts("NUM STATE ADDRESS  SYMBOL NAME      SAVE COUNT");
  63. //         xxx GROUP xxxxxxxx xxxxxxxxxxxxxxxx xxxx xxxxx
  64.     ScrPlain(); 
  65.     count++; 
  66.     ScrPutNewline(); 
  67.     maxLines--;
  68.  
  69.     while (topBP && i < maxLines) {
  70.         topBP--;
  71.         i = MAXBP - topBP;
  72.     }
  73.     for (i=topBP; i<MAXBP && maxLines > 0; i++, maxLines--) {
  74.         char *s = LookupValue((ULONG)bpTable[i].address);
  75.         if (!s) s = "";
  76.         ScrPrintf("%3d %-5.5s %08x %-16.16s %04x %5d",
  77.             i,
  78.             stateTable[bpTable[i].state],
  79.             bpTable[i].address,
  80.             s,
  81.             bpTable[i].value,
  82.             bpTable[i].count
  83.         );
  84.         count++; 
  85.         ScrPutNewline();
  86.     }
  87.     ScrPlain();
  88.     return count;
  89. }
  90.  
  91. void    InitBreakpoints(void) {
  92.     short    i;
  93.  
  94.     for (i=0; i<MAXBP; i++) bpTable[i].state = BP_UNSET;
  95.     bpTemp.state = BP_UNSET;
  96. }
  97.  
  98. void    SetAllBreakpoints(void) {
  99.     short    i;
  100.  
  101.     for (i=0; i<MAXBP; i++) {
  102.         if ((bpTable[i].state == BP_UNSET) && (bpTable[i].address)) {
  103.             bpTable[i].state = BP_SET;
  104.             bpTable[i].count = 1;
  105.         }
  106.     }
  107. }
  108.  
  109. void    InstallBreakpoints(void) {
  110.     short    i;
  111.  
  112.     // better flush those caches, this is like self modifying code
  113.     if(((struct Library *)SysBase)->lib_Version >= 36)CacheClearU();
  114.     for (i=0; i<MAXBP; i++) {
  115.         if (bpTable[i].state != BP_UNSET) *bpTable[i].address = 0x4afc; // ILLEGAL
  116.     }
  117.     if (bpTemp.state != BP_UNSET) *bpTemp.address = 0x4afc;
  118.     if(((struct Library *)SysBase)->lib_Version >= 36)CacheClearU();
  119. }
  120.  
  121. void    CheckBreakpoints(void) {
  122.     short    i;
  123.  
  124.     for (i=0; i<MAXBP; i++) {
  125.         if (bpTable[i].state != BP_UNSET) {
  126.             *bpTable[i].address = bpTable[i].value;
  127.             if (programPC == (ULONG)bpTable[i].address) {
  128.                 programState = STATE_BREAKPOINT;
  129.                 if (!(--bpTable[i].count)) {
  130.                     bpTable[i].state = BP_UNSET;
  131.                 }
  132.             }
  133.             if (bpTable[i].state == BP_GROUP) {
  134.                 bpTable[i].state = BP_UNSET;
  135.             }
  136.         }
  137.     }
  138.     if (bpTemp.state != BP_UNSET) {
  139.         *bpTemp.address = bpTemp.value;
  140.         if (programPC == (ULONG)bpTemp.address) programState = STATE_STEPPEDOVER;
  141.         bpTemp.state = BP_UNSET;
  142.     }
  143.     if (programPC == (ULONG)TargetExit) programState = STATE_EXITED;
  144. }
  145.  
  146. BOOL    IsBreakpoint(ULONG address) {
  147.     short    i;
  148.  
  149.     if(address = ValidMemCheck(address)) {    
  150.         for (i=0; i<MAXBP; i++) {
  151.         if (bpTable[i].state != BP_UNSET && address == (ULONG)bpTable[i].address) return TRUE;
  152.         }
  153.     }
  154.     return FALSE;
  155. }
  156.  
  157. BOOL    SetBreakpoint(ULONG address, UWORD count, UWORD type) {
  158. short i;
  159.  
  160.     if(address = ValidMemCheck(address)) {
  161.         for (i=0; i<MAXBP; i++) {
  162.         // check for first completely empty slot first
  163.         if ((bpTable[i].state == BP_UNSET) && !bpTable[i].address || ((ULONG)bpTable[i].address == address))
  164.         return setbp(i, address, count, type);
  165.         }
  166.         for (i=0; i<MAXBP; i++) {    // try for the first unset breakpoint
  167.             if (bpTable[i].state == BP_UNSET)return setbp(i, address, count, type);
  168.         }
  169.     }
  170.     return FALSE;
  171. }
  172.  
  173. BOOL    setbp(short i, ULONG address, UWORD count, UWORD type) {
  174.     bpTable[i].state = type;
  175.     bpTable[i].address = (UWORD *)address;
  176.     bpTable[i].value = *bpTable[i].address;
  177.     bpTable[i].count = count;
  178.     return TRUE;
  179. }
  180.  
  181. BOOL    ClearBreakpoint(ULONG address) {
  182.     short    i;
  183.  
  184.     for (i=0; i<MAXBP; i++) {
  185.         if (bpTable[i].state != BP_UNSET && address == (ULONG)bpTable[i].address) {
  186.             bpTable[i].state = BP_UNSET;
  187.             return TRUE;
  188.         }
  189.     }
  190.     return FALSE;
  191. }
  192.  
  193. void    SetTempBreakpoint(ULONG address) {
  194.     bpTemp.state = BP_SET;
  195.     bpTemp.address = (UWORD *)address;
  196.     bpTemp.value = *bpTemp.address;
  197. }
  198.  
  199.  
  200.